var fs = require('fs');
var path = require('path');
var DxfStruct = require('./DxfStruct2');
var DxfParser = require('../');

var DXF_FILE_PATH = path.join(__dirname, 'data', 'GZzhenfeng.dxf');
var OUTPUT_FILE_NAME = "cad.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });
var parser = new DxfParser();
var layer_color = {}

parser.parseStream(fileStream, function (err, dxf) {
    if (err) return console.error(err.stack);
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));

    dxf.sys = { start: 0, points: [], dn: 300 }
    dxfstruct = new DxfStruct(dxf)

    var newLayer = {
        layer: ['0', '管网'],
        //hatch: ['0'],
        //blocks: false,
        text: {
            '0': '标识标注',
        },
        clayer: {
            '管网': {
                '1284936': 'DN600',
                '10066743': 'DN250',
                '11096992': 'DN400',
            }
        },
        new: {
            '管网': 'DN200'
        },
        lineType:{
            '管网': {
                'ACAD_ISO12W100': 'DN300',
                //'ByLayer': 'DN200',
                'JIS_08_15': 'DN150',
                'HIDDEN': 'DN100',
            }
        },
        tlayers: {
            '标识标注': { c: '12237498', b: false },
            '0': { c: '12237498', b: false },
            // 'road': { c: '12237498', b: false },
            // '图层1': { c: '11382189', b: false },
            // '图层3': { c: '0', b: false },

            'DN100': { c: '2278314', b: true },
            'DN150': { c: '9543307', b: true },
            'DN200': { c: '24234', b: true },
            'DN250': { c: '2851357', b: true },
            'DN300': { c: '39129', b: true },
            'DN400': { c: '15119872', b: true },
            'DN600': { c: '12660276', b: true }
        },
        //'4321','2110','注记'
        merge: ['0']
    }
    
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf.entities));//entities,tables
    dxfstruct.setShowLayers(newLayer)
    dxfstruct.resetDxf('user')

    console.log('dxfstruct', dxfstruct.dxf.entities.length)
    fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf));
    //console.log(dxfstruct.getDxfStruct())
});